package com.tbgov.entity.pojo;

import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.List;

/**
 * @author u-1st
 */
@Data
@Schema( description = "简化分页实体类（PageInfo --> ResultPage）")
@AllArgsConstructor
public class ResultPage<T> implements Serializable {

    @Schema(description="页码")
    private int pageNum;
    @Schema(description="页数")
    private int pageSize;
    @Schema(description="页面")
    private int pages;
    @Schema(description="查询总数")
    private long total;
    @Schema(description="是否有下一页")
    private boolean hasNextPage;
    @Schema(description="结果集")
    private List<T> list;

    @Schema(description="根据相关业务需求看是否进行赋值 任意对象")
    private Object extra;


    public ResultPage(PageInfo<T> pageInfo) {
        BeanUtils.copyProperties(pageInfo, this);
    }

    public static <T> ResultPage<T> getList(PageInfo<T> pageInfo) {
        return new ResultPage<>(pageInfo);
    }

    public static <T> ResultPage<T> getList(List<T> list) {
        return getList(PageInfo.of(list));
    }
}
